from django.db import models


class Student(models.Model):
    
    class Mate:
        db_table = 'students'

    name = models.CharField(primary_key=True, max_length=30, verbose_name='姓名')
    age = models.PositiveSmallIntegerField(verbose_name='年龄')

    def __repr__(self):
        return '{} {}'.format(self.name, self.age)

    __str__ = __repr__


class Score(models.Model):
    
    class Mate:
        db_table = 'scroes'

    id = models.AutoField(primary_key=True)
    exam_subjects = models.CharField(max_length=40, verbose_name='科目')
    score = models.PositiveSmallIntegerField(verbose_name='分数')
    name = models.ForeignKey(Student, db_column='name', on_delete=models.CASCADE)

    def __repr__(self):
        return '{} {} {}'.format(self.exam_subjects, self.score, self.name_id)

    __str__ = __repr__
    
